namespace :db do
  namespace :init do
    desc "init_data"
    task :data => :environment do
      # work_item_type
      ['住宅','公建','别墅','多层','高层','普通','高层一类','高层二类','宾馆','中央空调','星级宾馆'].each_with_index do |name,index|
        WorkItemType.new(
          :name => name,
          :position => index
        ).save
      end

      #departments
      departments = ['方案组','园林组','建筑组','结构组','设备组']
      departments.each_with_index do |name, index |
        Department.new(
          :name => name,
          :position => index
        ).save
      end
      
      # designers
      ['陈燕','冯行宁','蒙美锦','甘福居','刘忠义','金威','王志军'].each do |full_name|
        Designer.new(
          :full_name => full_name,
          :department_id => Department.find_by_name(departments[rand(4)]).id
        ).save
      end
    end      
  end
end